﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;

namespace MCEMediaManager.Model
{
    public class Series
    {
        #region Private Properties
        private int _ID;
        private int _TvdbID;
        private string _Name = "";
        private string _Overview = "";
        private string _ContentRating = "";
        private decimal _Rating;
        private DateTime _OriginalAirDate;
        private string _Status = "";
        private string _Banner = "";
        private string _FanArt = "";
        private int _Runtime;

        #endregion
        #region Public Properties

        public int ID
        {
            get
            {
                return _ID;
            }
            set
            {
                _ID = value;
            }
        }

        public int TvdbID
        {
            get
            {
                return _TvdbID;
            }
            set
            {
                _TvdbID = value;
            }
        }

        public string Name
        {
            get
            {
                return _Name;
            }
            set
            {
                _Name = value;
            }
        }

        public string Overview
        {
            get
            {
                return _Overview;
            }
            set
            {
                _Overview = value;
            }
        }

        public string ContentRating
        {
            get
            {
                return _ContentRating;
            }
            set
            {
                _ContentRating = value;
            }
        }

        public decimal Rating
        {
            get
            {
                return _Rating;
            }
            set
            {
                _Rating = value;
            }
        }

        public DateTime OriginalAirDate
        {
            get
            {
                return _OriginalAirDate;
            }
            set
            {
                _OriginalAirDate = value;
            }
        }

        public string Status
        {
            get
            {
                return _Status;
            }
            set
            {
                _Status = value;
            }
        }

        public string Banner
        {
            get
            {
                return _Banner;
            }
            set
            {
                _Banner = value;
            }
        }

        public string FanArt
        {
            get
            {
                return _FanArt;
            }
            set
            {
                _FanArt = value;
            }
        }

        public int Runtime
        {
            get
            {
                return _Runtime;
            }
            set
            {
                _Runtime = value;
            }
        }
        #endregion

        public void LoadFromReader(IDataReader dr)
        {
            PropertyInfo[] props = this.GetType().GetProperties();
            foreach (PropertyInfo prop in props)
            {
                try
                {
                    prop.SetValue(this, dr[prop.Name], null);
                }
                catch
                {
                }
            }
        }

        public void LoadFromTvdbSearchResults(TvdbLib.Data.TvdbSearchResult result)
        {
            this.Name = result.SeriesName;
            this.Overview = result.Overview;
            this.Banner = result.Banner.BannerPath;
            this.OriginalAirDate = result.FirstAired;
            this.TvdbID = result.Id;
        }
    }
}
